<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/2 0002
 * Time: 上午 10:50
 */
class Tool{

    protected $CI;

    // We'll use a constructor, as you can't directly call a function
    // from a property definition.
    public function __construct()
    {
        // Assign the CodeIgniter super-object
        $this->CI =& get_instance();
    }

    public function getCaptcha()
    {
        $this->CI->load->helper('captcha');
       // $this->load->helper('captcha');
        $vals = array(
            'img_path'  => $this->CI->config->item('captcha_path'),
            'img_url'   => base_url($this->CI->config->item('captcha_path')),
            'img_width' => 150,
            'img_height'    => 35,
            'expiration'    => 3600,
            'word_length'   => 5,
            'font_size' => 20,
            'font_path'     => $this->CI->config->item('captcha_path').'fonts/calibrib.ttf',   //验证码上字体
            'pool'          => '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX'
        );

        $cap = create_captcha($vals);

        //var_dump($cap);
        /***
        $data = array(
            'captcha_time'  => $cap['time'],
            'ip_address'    => $this->input->ip_address(),
            'word'      => $cap['word']
        );***/
       $_SESSION['captcha'] = hash_hmac("sha256",$cap['word'],"ci&captcha");
        return $vals['img_url'].$cap['filename'];
    }


   public function verifyCaptcha($test){

      if(hash_hmac("sha256",$test,"ci&captcha")===$_SESSION['captcha']){
          return true;
      }else{
          return false;
      }


   }

    public function createPassword($test){

        return hash_hmac("sha256",$test,"ci&password");


    }





    public function test(){

        return 11112;
    }




}